package logic

import (
	"context"
	"zhihu/mobels/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowTopProblemLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowTopProblemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowTopProblemLogic {
	return &ShowTopProblemLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowTopProblemLogic) ShowTopProblem(in *zhihurpc.ShowTopProblemRequest) (*zhihurpc.ShowTopProblemResponse, error) {
	// todo: add your logic here and delete this line
	var problem []mysql.Problem
	var hot []*zhihurpc.ShowTopProblem
	mysql.DB.Order("hot desc").Limit(10).Find(&problem)
	for _, m := range problem {
		list := zhihurpc.ShowTopProblem{
			Title:     m.Title,
			Content:   m.Content,
			ProblemId: int64(m.ID),
		}
		hot = append(hot, &list)
	}

	return &zhihurpc.ShowTopProblemResponse{List: hot}, nil
}
